package com.board.ibatitses;

import java.io.IOException;
import java.io.Reader;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
public abstract class SqlDaoSupport {
	private SqlMapClient sqlMapper;

	public SqlDaoSupport(String path) {
		if(sqlMapper==null){
			try {
				Reader reader=Resources.getResourceAsReader(path);
				sqlMapper=SqlMapClientBuilder.buildSqlMapClient(reader);
				reader.close();
			} catch (IOException e) {
				throw new RuntimeException("Check the location of SqlMapClient." , e);
			}
		}
	}

	public SqlDaoSupport() {
		this("com/board/ibatis/sqlconfig/SqlMapConfig.xml");
	}
	
	public SqlMapClient getSqlMapClient(){
		return sqlMapper;
	}	
}